﻿using MongoDB.Driver;
using Sustainalytics.ClientDW.Synchronization.SyncESGData.AbstractClassesAndInterfaces;
using Sustainalytics.SharedEntities.EsgResearch.PartialEsgResearch;
using Sustainalytics.Synchronization.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Sustainalytics.ClientDW.Synchronization.SyncESGData.RPCompanyProfileLogic
{
    public class RPCompanyProfileCommand : SyncEsgCommand<RPCompanyProfile>
    {
        private readonly IMongoCollection<RPCompanyProfile> rPCompanyProfileCollection;

        public RPCompanyProfileCommand(IMongoCollection<RPCompanyProfile> rPCompanyProfileCollection, ILogger logger) : base(logger)
        {
            this.rPCompanyProfileCollection = rPCompanyProfileCollection;
        }

        protected override async Task<DeleteResult> DeleteAssociatedRecordsAsync(IEnumerable<Guid> companiesIds, Guid? additionalDiscriminator = null)
        {
            return await rPCompanyProfileCollection.DeleteManyAsync(x => companiesIds.Contains(x.Id)).ConfigureAwait(false);
        }

        protected override async Task InsertRecordsAsync(IEnumerable<RPCompanyProfile> entities)
        {
            await rPCompanyProfileCollection.InsertManyAsync(entities).ConfigureAwait(false);
        }
    }
}
